/*using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;*/

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using OmegaEngine;

namespace XNAEngineTest
{
    /// <summary>
    /// This is the main type for your game
    /// </summary>
    public class Game1 : Microsoft.Xna.Framework.Game
    {
        // Paused
        bool paused = false;

        // The IGraphicsDeviceService the engine will use
        GraphicsDeviceManager graphics;

        // FPS Label
        GUILabel FPSLabel;

        // FPS Label
        GUIBackground MousePointer;

        // FPS Logic
        float elapsed = 0;
        static int count = 0;
        // Fired
        // bool fired = false;

        public Game1()
        {
            // Setup Graphics
            graphics = new GraphicsDeviceManager(this);
            graphics.PreferredBackBufferWidth = 800;
            graphics.PreferredBackBufferHeight = 600;
            graphics.ApplyChanges();
            //Game1.count++;
        }

        protected override void LoadContent()
        {
            //this.IsFixedTimeStep = false;

            // Setup Engine. We do this in the load method so that we know graphics will be ready for use
            Engine.SetupEngine(graphics, graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight);

            // Create a new ClearScreen. It will automatically be set set as the engine's DefaultScreen, currently Engine.BackGroundScreen
            GameScreen GS = new GameScreen("Main");
            Engine.DefaultScreen = GS;

            // Create a new Camera
            Camera camera = new FPSCamera();

            // Setup Physics
            Engine.Services.AddService(typeof(Physics), new Physics());

            // Setup Error handling
            Engine.Services.AddService(typeof(Error), new Error());

            // Setup the Console
            Engine.Services.AddService(typeof(OmegaConsole), new OmegaConsole());
            
            // Create a new Player
            Player player = new Player(Engine.Content.Load<Model>("Content/basketball"),
                new SphereObject(1f, new Vector3(3, 3, 5), new Vector3(0, 0, 0)),
                camera, GS);
                //new FPSCamera(), GS);
                //new TPSCamera(new Vector3(0, 10, -10)));

            player.cam.Position = new Vector3(3, 3, 5);

            GUIBackground Crosshair = new GUIBackground(Engine.Content.Load<Texture2D>("Content/crosshair"),
                                                   336, 226, Color.White, GS);

            FPSLabel = new GUILabel("FPS: ", Engine.DefaultFont, 10, 10, Color.White, GS);

            // Add it to the service container
            Engine.Services.AddService(typeof(Camera), camera);
 
            // Setup Keyboard
            KeyboardDevice keyboard = new KeyboardDevice();
            Engine.Services.AddService(typeof(KeyboardDevice), keyboard);

            // Setup Mouse
            MouseDevice mouse = new MouseDevice();
            Engine.Services.AddService(typeof(MouseDevice), mouse);

            // Load the mdel we will use for our boxes
            Model model = Engine.Content.Load<Model>("Content/ig_box");

            setUpPlanes();

            // Create the stack of boxes
            for (int y = 0; y < 3; y++)
            {
                for (int x = 0; x < 3; x++)
                {
                    FallingBox act = new FallingBox(model, new BoxObject(
                        new Vector3(.5f),
                        new Vector3(-.5f + (x * 0.52f), .5f + (y * 0.52f), -1),
                        Vector3.Zero), GS);

                    act.Scale = new Vector3(.5f);

                    GS.AddComponent(act);
                }
            }

            // Create a new actor
            //Actor actor = new Actor(Engine.Content.Load<Model>("Content/ig_box"), new Vector3(0, 0, 0));
            //actor.DrawOrder = 2;

            base.LoadContent();
        }

        protected override void Update(GameTime gameTime)
        {
            KeyboardDevice keyboard = Engine.Services.GetService<KeyboardDevice>();
            MouseDevice mouse = Engine.Services.GetService<MouseDevice>();

            // Pause Menu
            if (keyboard.WasKeyPressed(Keys.Escape))
            {
                if (!Engine.GameScreens.Contains("Pause"))
                {
                    GameScreen PM = new PauseScreen("Pause");
                    GUIBackground BG = new GUIBackground(Engine.Content.Load<Texture2D>("Content/pause"),
                                                   0, 0, Engine.ScreenWidth, Engine.ScreenHeight, new Color(255, 255, 255, 192), PM);
                    GUICheckBoxLabel cb = new GUICheckBoxLabel("Test", 200, 200, 20, 20, Color.White, PM);
                    GUIBackgroundButton rawr = new GUIBackgroundButton(Engine.Content.Load<Texture2D>("Content/x"), PM.Disable,
                                                    (Engine.ScreenWidth - 26), 10, new Color(255, 255, 255, 255), PM);
                    GUILabelButton lb = new GUILabelButton("Close", PM.Disable, Engine.DefaultFont, 40, 100, Color.White, PM);
                    GUILabel label = new GUILabel("Pause\nMenu", Engine.DefaultFont, 300, 300, Color.White, PM); 
                    MousePointer = new GUIBackground(Engine.Content.Load<Texture2D>("Content/cursor"), 0, 0, PM);
                }
                else
                {
                    Engine.GameScreens["Pause"].Disable();
                }

                this.paused = !this.paused;
            }

            if (MousePointer != null && MousePointer.Visible)
            {
                Rectangle rect = MousePointer.Rectangle;

                rect.X = (int)mouse.Position.X;
                rect.Y = (int)mouse.Position.Y;

                MousePointer.Rectangle = rect;
            }

            // Update the engine and game
            Engine.Update(gameTime);

            base.Update(gameTime);
        }
       
        protected override void Draw(GameTime gameTime)
        {
            elapsed = (float)gameTime.ElapsedGameTime.TotalSeconds;

            FPSLabel.UpdateText("FPS: " + (1 / elapsed).ToString());

            // Draw the engine and game
            Engine.Draw(gameTime, ComponentType.All);
            
            base.Draw(gameTime);
        }

        protected void setUpPlanes()
        {
            GameScreen GS = Engine.GameScreens["Main"];

            // Create the p;ane and make it immovable
            PhysicsActor plane = new PhysicsActor(
                Engine.Content.Load<Model>("Content/ig_plane"),
                //new BoxObject(new Vector3(40, 1f, 40), new Vector3(0, -20f, 0), new Vector3(0, 0, 0)));
                new PlaneObject(new Vector3(0, -20f, 0)), GS);
            plane.PhysicsObject.Immovable = true;
            plane.Scale = new Vector3(10, 1, 10);

            GS.AddComponent(plane);

            PhysicsActor plane2 = new PhysicsActor(
                Engine.Content.Load<Model>("Content/ig_plane"),
                new BoxObject(new Vector3(40, 1f, 40), new Vector3(0, 20f, 0), new Vector3(0, 0, MathHelper.Pi)), GS);
            plane2.PhysicsObject.Immovable = true;
            plane2.Scale = new Vector3(10, 1, 10);

            GS.AddComponent(plane2);

            PhysicsActor plane3 = new PhysicsActor(
                Engine.Content.Load<Model>("Content/ig_plane"),
                new BoxObject(new Vector3(40, 1f, 40), new Vector3(0, 0, 20f), new Vector3(-MathHelper.PiOver2, 0, 0)), GS);
            plane3.PhysicsObject.Immovable = true;
            plane3.Scale = new Vector3(10, 1, 10);

            GS.AddComponent(plane3);

            PhysicsActor plane4 = new PhysicsActor(
                Engine.Content.Load<Model>("Content/ig_plane"),
                new BoxObject(new Vector3(40, 1f, 40), new Vector3(0, 0, -20f), new Vector3(MathHelper.PiOver2, 0, 0)), GS);
            plane4.PhysicsObject.Immovable = true;
            plane4.Scale = new Vector3(10, 1, 10);

            GS.AddComponent(plane4);

            PhysicsActor plane5 = new PhysicsActor(
                Engine.Content.Load<Model>("Content/ig_plane"),
                new BoxObject(new Vector3(40, 1f, 40), new Vector3(20f, 0, 0), new Vector3(0, 0, MathHelper.PiOver2)), GS);
            plane5.PhysicsObject.Immovable = true;
            plane5.Scale = new Vector3(10, 1, 10);

            GS.AddComponent(plane5);

            PhysicsActor plane6 = new PhysicsActor(
                Engine.Content.Load<Model>("Content/ig_plane"),
                new BoxObject(new Vector3(40, 1f, 40), new Vector3(-20f, 0, 0), new Vector3(0, 0, -MathHelper.PiOver2)), GS);
            plane6.PhysicsObject.Immovable = true;
            plane6.Scale = new Vector3(10, 1, 10);

            GS.AddComponent(plane6);
        }
    }
}
